#!/usr/bin/env bash

set -e

cd -- "$(dirname -- "$0")/.."

# update list item docs to account for custom code
cat << EOT >> examples/resources/cloudflare_list_item/import.sh
$ terraform import cloudflare_list_item.example '<account_id>/<list_id>/<item_id>'
EOT

echo "==> Generating Terraform provider documentation"

EXEC='tfplugindocs'
if ! command -v -- "$EXEC" &> /dev/null; then
  go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs
  EXEC="$(go env -- GOPATH)/bin/$EXEC"
fi

case "$OSTYPE" in
linux*)
  export -- TMPDIR=/var/tmp
  ;;
*) ;;
esac

go mod tidy
exec -- "$EXEC" generate -rendered-provider-name "Cloudflare" -provider-name="cloudflare"
